package com.zzz.mcpclient.controller;

import com.zzz.mcpclient.request.ChatMessageRequest;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
public class TestController {

    @Autowired
    private ChatClient chatClient;
    @PostMapping(value = "/ai/answer")
    public String generate(@RequestBody ChatMessageRequest request) {
        return chatClient.prompt().system("你是一个全能的助手，使用提供的工具解答用户的问题，回答的最后给出调用的哪些工具.")
                .user(request.getContent())
                .call()
                .content();
    }


    @PostMapping(value = "/ai/answer/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> generateStreamAsString( @RequestBody ChatMessageRequest request) {
        Flux<String> content = chatClient.prompt()
                .user(request.getContent())
                .stream()
                .content();
        return content
                .concatWith(Flux.just("[complete]"));

    }
}
